package edu.guet.server.service;

import edu.guet.server.mapper.UHomeorkMapper;
import edu.guet.server.model.UHomework;
import edu.guet.server.model.vo.StuHmkVO;
import edu.guet.server.utils.ResultAPI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional
@Service
public class TeacherHmkService {
    @Autowired
    UHomeorkMapper homeworkMapper;
    public UHomework getHmkByid(Integer hmkId) {
        return homeworkMapper.getHmkByid(hmkId);
    }

    public ResultAPI updateHmk(UHomework uHomework) {
        boolean flag=homeworkMapper.updateHmk(uHomework);
        if(flag){
            return ResultAPI.success();
        }
        return ResultAPI.error("更新失败！");
    }

    public ResultAPI deleteHmk(Integer hmkId) {
        boolean flag=homeworkMapper.deleteHmk(hmkId);
        if(flag){
            return ResultAPI.success();
        }
        return ResultAPI.error("更新失败！");
    }

    public ResultAPI insertHmk(UHomework uHomework) {
        boolean flag=homeworkMapper.insertUnitHmk(uHomework);
        if(flag){
            return ResultAPI.success(uHomework);
        }
        return ResultAPI.error("添加失败！");
    }

    public ResultAPI getlistByhmkid(Integer hmk_id) {
        List<StuHmkVO> stuHmkVOS=homeworkMapper.getlistByhmkid(hmk_id);
        return ResultAPI.success(stuHmkVOS);
    }

    public ResultAPI getHmklistbySem(Integer semesterId) {
        List<UHomework> uHomeworkList=homeworkMapper.getHmklistbySem(semesterId);
        return ResultAPI.success(uHomeworkList);
    }

    public ResultAPI updateGrade(StuHmkVO uHomework) {
        boolean flag=homeworkMapper.updateGrade(uHomework);
        if(flag){
            return ResultAPI.success(uHomework);
        }
        return ResultAPI.error("批改失败！");
    }
}
